jQuery(document).ready(function() { 
/* MEDIA UPLOADER */
	var uploadID = '';
	
	jQuery('.upload-button').click(function() {
		uploadID = jQuery(this).prev('input'); /*set the uploadID variable to the value of the input before the upload button*/
		formfield = jQuery('.upload').attr('name');
		tb_show('', 'media-upload.php?post_id=301&amp;type=image&amp;TB_iframe=1');
		return false;
	});
	
	window.send_to_editor = function(html) {				
		var class_string    = jQuery( 'img', html ).attr( 'class' );
		var classes = class_string.split( /\s+/ );
		for ( var i = 0; i < classes.length; i++ ) {
			var source = classes[i].match(/wp-image-([0-9]+)/);
			if ( source && source.length > 1 ) {
				image_id = parseInt( source[1] );
			}
		}				
		uploadID.val(image_id);
		tb_remove();
	};
}); 